package top.codedance.iotp.server.net.handle.configuration;

import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.server.net.handle.WsReceiveHandler;
import top.codedance.iotp.server.net.handle.subhandle.controller.WsController;
import top.codedance.iotp.server.net.handle.subhandle.controller.http.async.*;

import java.util.HashMap;
import java.util.Map;

public class WsRouteConfig {

    /**
     * websocket request route
     * @return
     */
    public static Map<String, WsController> getConfig(){
        HashMap<String, WsController> routeConfig = new HashMap<>();

        /**
         * 获取com数据
         * request:
         *    {
         *   "username": "xuedianfu",
         *   "password": "123456",
         *   "deviceId": "Djds7324dsfSDkjEPm",
         *   "agreement": "com",
         *   "client": {
         *      "cmd": "0169323031303003"
         *   }
         * }
         */
        routeConfig.put("com", new ComExecController());

        /**
         * 获取udp数据
         * request:
         *    {
         *   "username": "xuedianfu",
         *   "password": "123456",
         *   "deviceId": "Djds7324dsfSDkjEPm",
         *   "agreement": "udp",
         *   "client": {
         *      "cmd": "0169323031303003"
         *   }
         * }
         */
        routeConfig.put("udp", new UdpExecController());

        /**
         * 获取OPC数据
         * request:
         *    {
         *   "username": "xuedianfu",
         *   "password": "123456",
         *   "deviceId": "Djds7324dsfSDkjEPm",
         *   "agreement": "opc",
         *   "client": {
         *      "instance": 0,
         *      "items": [
         *          "tag": "a", "ext": ""
         *       ]
         *   }
         * }
         */
        routeConfig.put("opc", new OpcExecController());

        /**
         * 获取系统数据
         * request:
         *    {
         *   "username": "xuedianfu",
         *   "password": "123456",
         *   "deviceId": "Djds7324dsfSDkjEPm",
         *   "agreement": "system",
         *   “client”: {
         *      "command": "netstat -tnlp" 或 "cmd": "netstat -ano", "powershell": true
         *   }
         * }
         */
        routeConfig.put("system", new SystemExecController());

        /**
         * mqtt接口
         * request:
         *    {
         *     "username": "admin",
         *     "password": "codedance2021",
         *     "deviceId": "Djds7324dsfSDkjEPm",
         *     "agreement": "mqtt"，
         *     "client": {
         *         "instance": 0
         *     }   //此选项可选
         * }
         */
        routeConfig.put("mqtt", new MqttExecController());

        /**
         * push接口
         * request:
         *    {
         *     "username": "admin",
         *     "password": "codedance2021",
         *     "deviceId": "Djds7324dsfSDkjEPm",
         *     "agreement": "push"，
         *     "client": {
         *         "instance": 0
         *     }   //此选项可选
         * }
         */
        routeConfig.put("push", new PushExecController());

        /**
         * 客户端上下线状态接口
         * request:
         *    {
         *     "username": "admin",
         *     "password": "codedance2021",
         *     "deviceId": "Djds7324dsfSDkjEPm",
         *     "agreement": "cstatus"
         *    }
         */
        routeConfig.put("cstatus", new ClientsStatusHandler());

        /**
         * 获取BACNet数据
         * request:
         *    {
         *   "username": "xuedianfu",
         *   "password": "123456",
         *   "deviceId": "Djds7324dsfSDkjEPm",
         *   "agreement": "bacnet",
         *   "client": {
         *      "instance": 0,
         *      "items": [
         *          {"tag": "tag1", "deviceId": 3113167, "property": 85, "datatype": 0, "instance": 0},
         *          {"tag": "tag2", "deviceId": 3113167, "property": 85, "datatype": 19, "instance": 0, "isWrite": true, "value": 88},
         *       ]
         *   }
         * }
         */
        routeConfig.put("bacnet", new BacNetExecController());

        return routeConfig;
    }

    /**
     * websocket respose route
     * @return
     */
    public static Map<Short, WsReceiveHandler> getWsReceiveHandlers(){
        HashMap<Short, WsReceiveHandler> receiveConfig = new HashMap<>();
        receiveConfig.put(Command.ASYNC_SYSTEM_COMMAND_RECEIVE, new SystemReceiveHandler());
        receiveConfig.put(Command.ASYNC_OPC_COMMAND_RECEIVE, new OpcReceiverHandler());
        receiveConfig.put(Command.ASYNC_COM_COMMAND_RECEIVE, new ComReceiverHandler());
        receiveConfig.put(Command.ASYNC_UDP_COMMAND_RECEIVE, new UdpReceiverHandler());
        receiveConfig.put(Command.ASYNC_MQTT_COMMAND_RECEIVE, new MqttReceiverHandler());
        receiveConfig.put(Command.ASYNC_PUSH_DATA_COMMAND_RECEIVE, new PushReceiveHandler());
        receiveConfig.put(Command.ASYNC_CSTATUS_COMMAND_RECEIVE, new ClientsStatusReceiverHandler());
        receiveConfig.put(Command.ASYNC_BACNET_COMMAND_RECEIVE, new BacNetReceiverHandler());
        return receiveConfig;
    }
}
